﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Services.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ToolHelp;

namespace SerilLogWebApplication.Controllers
{
    [ApiVersion("1.0", Deprecated = false)] //Deprecated是否弃用该版本 默认为false不弃用。即使标记了弃用此接口还是会显示，只是做个提示此版本将会被弃用了。
    [ApiController]
    [Route("[controller]/[action]")]
    public class WeatherForecastController : BaseController
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };
        
        private readonly ILogger<WeatherForecastController> _logger;
        private readonly IPersonService  _personService; 
        public WeatherForecastController(ILogger<WeatherForecastController> logger, IPersonService personService)
        {
            _logger = logger;
            _personService = personService;
        }

        [HttpGet]
        public IEnumerable<WeatherForecast> Get()
        {
            var rng = new Random();
            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
                Summary = Summaries[rng.Next(Summaries.Length)]
            })
            .ToArray();
        }
        [HttpGet]
        public string GetAll()
        {
            var name = _personService.DoWork2();
            var value1 = ConfigHelper.GetValue("DBConfig:Sqlserver");
            var rng = new Random();
            SerilLogHelper.WarnLog($"小乌龟");
            return "OK";
        }
    }
}
